Skip to content

feat: add dynamic sitemap generation and API endpoint#1459

Open
kelvinkipruto wants to merge 8 commits intomainfrom
ft/sitemap
Open

feat: add dynamic sitemap generation and API endpoint#1459
kelvinkipruto wants to merge 8 commits intomainfrom
ft/sitemap

Conversation

@kelvinkipruto
Copy link
Copy Markdown
Contributor

Description

Implement sitemap generation functionality with a new API endpoint at /api/v1/sitemap. The sitemap includes all published pages (excluding error pages).

  • Add sitemap.xml rewrite rule in Next.js config
  • Create sitemap API endpoint handler
  • Implement sitemap generation utilities including URL normalization and deduplication

Fixes # (issue)

Type of change

  • New feature (non-breaking change which adds functionality)

Screenshots

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation

Implement sitemap generation functionality with a new API endpoint at `/api/v1/sitemap`. The sitemap includes all published pages (excluding error pages) with proper URL formatting, last modified dates, and XML escaping. This improves SEO by providing search engines with an up-to-date sitemap.

- Add sitemap.xml rewrite rule in Next.js config
- Create sitemap API endpoint handler
- Implement sitemap generation utilities including URL normalization and deduplication
- Export getSitemapXml function from data layer
@kelvinkipruto

This comment was marked as resolved.

@kelvinkipruto kelvinkipruto marked this pull request as ready for review April 16, 2026 09:54
@claude

This comment was marked as resolved.

@chatgpt-codex-connector

This comment was marked as resolved.

…dpoint

- Validate that only GET requests are allowed, returning 405 for other methods
- Add Cache-Control headers to improve performance and reduce server load
- Wrap sitemap generation in try-catch to handle errors gracefully
- Remove unnecessary escapeXml call for lastmod dates and simplify dedupe logic
- Make getSitemapEntries function private to module
@kelvinkipruto

This comment was marked as resolved.

@claude

This comment was marked as resolved.

Change getSitemapXml from named to default export for consistent import patterns
Add Sentry error capture to sitemap API endpoint for improved monitoring
@kelvinkipruto

This comment was marked as resolved.

@claude

This comment was marked as resolved.

@kelvinkipruto

This comment was marked as resolved.

@claude

This comment was marked as resolved.

Copy link
Copy Markdown
Member

@kilemensi kilemensi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏽


  1. We have more pages than just pages collection e.g. most of opportunities collection items also become pages.
  2. If you've addressed all comments, please hide them/mark them as resolved. Otherwise, it's hard to review not knowing if you should comment on something that already has a comment or not.

Comment thread apps/trustlab/src/lib/data/common/sitemap.js Outdated
Comment thread apps/trustlab/src/lib/data/common/sitemap.js
Comment thread apps/trustlab/src/lib/data/common/sitemap.js Outdated
Comment thread apps/trustlab/src/lib/data/common/sitemap.js
@kilemensi kilemensi added the enhancement New feature or request label Apr 16, 2026
@github-project-automation github-project-automation Bot moved this to 🚧 In Progress in COMMONS Apr 16, 2026
- Replace dynamic pathname generation with stored `pathname` field from CMS
- Filter pages by `_status: "published"` instead of just excluding error pages
- Remove XML escaping as URLs are already validated and safe
- Add Sentry warning for pages missing pathname to aid debugging
- Simplify code by removing deduplication and custom escape functions
Add a new function `getOpportunitiesEntries` to fetch and process opportunity documents for the sitemap. Refactor the warning logic for missing pathnames into a shared helper function `warnOnMissingPathname`. Use `Promise.all` to fetch pages and opportunities concurrently, improving efficiency.
@kelvinkipruto kelvinkipruto requested a review from kilemensi April 21, 2026 08:38
@kelvinkipruto
Copy link
Copy Markdown
Contributor Author

@claude @codex Review

@claude

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@kilemensi
Copy link
Copy Markdown
Member

Haven't looked at the new code yet @kelvinkipruto but my previous question still remains, why do we need we need to use pages/api and a redirect instead of just in pages?

Do we need to escape XML? e.g. https://nextjs.org/learn/seo/xml-sitemaps doesn't (and do we need this to be in pages/api instead of just pages?

The sitemap was previously served via an API route with a rewrite. This change replaces it with a static page (`sitemap.xml.page.js`) to improve performance and caching. The new page uses `getServerSideProps` to generate the XML with proper cache headers and error handling via Sentry.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: 🚧 In Progress

Development

Successfully merging this pull request may close these issues.

2 participants